<?php

/*
*第15讲 PHP生成HTML文件原理
*/

//fopen fread filesize fwrite fclose  r w  a
//unlink   mkdir

$con = array(array('新闻标题1','新闻内容1'),array('新闻标题2','新闻内容2'));
foreach($con as $id=>$val){
	$title = $val[0];
	$content = $val[1];
	$path = $id.".html";

	//文件读取
	$fp = fopen("tmp.html","r");
	$str = fread($fp,filesize("tmp.html"));
	$str = str_replace("{title}",$title,$str);
	$str = str_replace("{content}",$content,$str);
	fclose($fp);

	$handle = fopen($path,"w");
	fwrite($handle,$str);
	fclose($handle);
	echo '生成成功<br />';
}
//删除文件
$u = unlink("1.html");
if($u) echo '删除成功';

//新建目录
mkdir("a");

?>
